Implement source redirection
authorAlex Crichton <alex@alexcrichton.com>
Wed, 3 Feb 2016 18:54:07 +0000 (10:54 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 1 Aug 2016 17:14:52 +0000 (10:14 -0700)
commit8214bb953dee7f529747ce69ff81fe294259a6a0
tree73e0dc3758715066ac5c84a9884011f3ca430446
parent2b19333a1ba032831eb31c2e4a7b871942e5ee93
Implement source redirection

This commit implements a scheme for .cargo/config files where sources can be
redirected to other sources. The purpose of this will be to override crates.io
for a few use cases:

  * Replace it with a mirror site that is sync'd to crates.io
  * Replace it with a "directory source" or some other local source

This major feature of this redirection, however, is that none of it is encoded
into the lock file. If one source is redirected to another then it is assumed
that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in
both location). The lock file simply encodes the canonical soure (e.g.
crates.io) rather than the replacement source. In the end this means that
Cargo.lock files can be generated from any replacement source and shipped to
other locations without the lockfile oscillating about where packages came from.

Eventually this support will be extended to `Cargo.toml` itself (which will be
encoded into the lock file), but that support is not implemented today. The
syntax for what was implemented today looks like:

    # .cargo/config
    [source.my-awesome-registry]
    registry = 'https://example.com/path/to/index'

    [source.crates-io]
    replace-with = 'my-awesome-registry'

Each source will have a canonical name and will be configured with the various
keys underneath it (today just 'registry' and 'directory' will be accepted). The
global `crates-io` source represents crates from the standard registry, and this
can be replaced with other mirror sources.

All tests have been modified to use this new infrastructure instead of the old
`registry.index` configuration. This configuration is now also deprecated and
will emit an unconditional warning about how it will no longer be used in the
future.

Finally, all subcommands now use this "source map" except for `cargo publish`,
which will always publish to the default registry (in this case crates.io).
29 files changed:
src/bin/install.rs
src/bin/login.rs
src/cargo/core/package_id.rs
src/cargo/core/registry.rs
src/cargo/core/source.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_fetch.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/cargo_install.rs
src/cargo/ops/cargo_package.rs
src/cargo/ops/registry.rs
src/cargo/sources/config.rs [new file with mode: 0644]
src/cargo/sources/mod.rs
src/cargo/sources/registry.rs
src/cargo/sources/replaced.rs [new file with mode: 0644]
src/cargo/util/config.rs
src/cargo/util/toml.rs
tests/bad-config.rs
tests/build-script.rs
tests/cargo_alias_config.rs
tests/cargotest/support/registry.rs
tests/install.rs
tests/metadata.rs
tests/overrides.rs
tests/publish.rs
tests/registry.rs
tests/search.rs
tests/workspaces.rs